package org.example.struct.array;

/**
 * @author liyishan
 * @date 2024/1/2 10:37
 * @apiNote
 */

public class Test00258AddDigits {

    public static void main(String[] args) {
        System.out.println(addDigits(38));
    }

    public static int test(int num) {
        while(num >= 10){
            int sum = 0;
            while(num > 0){
                int temp = num % 10;
                sum += temp;
                num /= 10;
            }
            num = sum;
        }
        return num;
    }

    public static int addDigits(int num) {
        while(num >= 10){
            num = getNext(num);
        }
        return num;
    }

    public static int getNext(int num) {
        int sum = 0;
        while(num > 0){
            int temp = num % 10;
            sum += temp;
            num /= 10;
        }
        return sum;
    }
}
